package cn.fanqinghong.ymcc.mq.producer;

import cn.fanqinghong.ymcc.constants.MessageConstants;
import cn.fanqinghong.ymcc.domain.MessageEmail;
import cn.fanqinghong.ymcc.domain.MessageSms;
import cn.fanqinghong.ymcc.domain.MessageStation;
import cn.fanqinghong.ymcc.dto.EmailMessageDto;
import cn.fanqinghong.ymcc.dto.SmsMessageDto;
import cn.fanqinghong.ymcc.dto.StationMessageDto;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * FAN
 * 2022/7/25  11:28
 */
@Component
public class MessageHandlerProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送站内信
     * @param stationMessageDto
     */
    public void sendStationMeassage(StationMessageDto stationMessageDto){
        //为了方便消费者消费，把MessageStation封装成json对象
        String messageStationStr = JSON.toJSONString(stationMessageDto);
        //发单项消息，数据丢失不影响
        rocketMQTemplate.sendOneWay(MessageConstants.STATION_TOPIC + ":" + MessageConstants.STATION_TAGES, messageStationStr);
    }

    /**
     * 发送短信
     * @param smsMessageDto
     */
    public void sendSMSMessage(SmsMessageDto smsMessageDto){
        //为了方便消费者消费，把MessageStation封装成json对象
        String messageStationStr = JSON.toJSONString(smsMessageDto);
        //发单项消息，数据丢失不影响
        rocketMQTemplate.sendOneWay(MessageConstants.SMS_TOPIC + ":" + MessageConstants.SMS_TAGES, messageStationStr);
    }

    /**
     * 发送邮件
     * @param emailMessageDto
     */
    public void sendMessageEmail(EmailMessageDto emailMessageDto){
        //为了方便消费者消费，把MessageStation封装成json对象
        String messageStationStr = JSON.toJSONString(emailMessageDto);
        //发单项消息，数据丢失不影响
        rocketMQTemplate.sendOneWay(MessageConstants.EMAIL_TOPIC + ":" + MessageConstants.EMAIL_TAGES, messageStationStr);
    }


}
